
/**
 * 信息存储 正常的日志 错误分开记录 其它日志正常控制台输出
 * 作者：Yoyo
 */
const log4js = require("log4js");

const pkname = `[${CONFIG.projectName}]`;

module.exports = ({
    error = {
        filename: './mcInteract/logs/error/error.log',//存储路径
        compress: true,//是否每天的压缩存储
        level: 'error',//最低存储等级
        maxLevel: 'fatal'//最高存储等级
    },
    info = {
        filename: './mcInteract/logs/CurrentLog.log',//存储路径
        compress: true,//是否每天的压缩存储
        level: 'info',//最低存储等级
        maxLevel: 'warn'//最高存储等级
    },
    console = {
        level: 'trace'//最低输出等级
    }
} = {}) => {
    log4js.configure({
        appenders: {
            console: { type: "console" },
            appErr: { type: "dateFile", filename: error.filename, pattern: "yyyy-MM-dd.log", compress: error.compress },
            appFile: { type: "dateFile", filename: info.filename, pattern: "yyyy-MM-dd.log", compress: info.compress },
            "just-errors": {
                type: "logLevelFilter",
                appender: "appErr",
                level: error.level,
                maxLevel: error.maxLevel
            },
            "no-errors": {
                type: "logLevelFilter",
                appender: "appFile",
                level: info.level,
                maxLevel: info.maxLevel
            },
            "level-console": {
                type: "logLevelFilter",
                appender: "console",
                level: console.level
            }
        },
        categories: {
            default: { appenders: ["console"], level: "trace" },
            [pkname]: { appenders: ["just-errors", "no-errors", "level-console"], level: "trace" }
        },
    });


    

    const logger = log4js.getLogger(pkname);

    // logger.trace("Entering cheese testing");
    // logger.debug("Got cheese.");
    // logger.info("Cheese is Comté.");
    // logger.warn("Cheese is quite smelly.");
    // logger.error("Cheese is too ripe!");
    // logger.fatal("Cheese was breeding ground for listeria.");
    return logger;
};